<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>precise-range | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>precise-range</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>precise-range</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/plugins/preciserange/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/10-plugins/06-preciserange.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">npm install moment-precise-range-plugin
</code></pre>

							</div>
<p>&#x7531; <a href="javascript:window.open('http://nodejs.cn/s/cfGy7U');" target="_blank" rel="nofollow">Rob Dawson</a> &#x7F16;&#x5199;&#x7684; <a href="javascript:window.open('http://nodejs.cn/s/PT3BzZ');" target="_blank" rel="nofollow">Precise Range</a> &#x63D2;&#x4EF6;&#x53EF;&#x7528;&#x4E8E;&#x663E;&#x793A;&#x65E5;&#x671F;/&#x65F6;&#x95F4;&#x8303;&#x56F4;&#x7684;&#x51C6;&#x786E;&#x7684;&#x4EBA;&#x7C7B;&#x53EF;&#x8BFB;&#x7684;&#x8868;&#x793A;&#x5F62;&#x5F0F;&#xFF1A;</p>
<pre><code class="language-javascript">moment(&quot;2014-01-01 12:00:00&quot;).preciseDiff(&quot;2015-03-04 16:05:06&quot;);
 // 1 year 2 months 3 days 4 hours 5 minutes 6 seconds
</code></pre>
<pre><code class="language-javascript">moment.preciseDiff(&quot;2014-01-01 12:00:00&quot;, &quot;2014-04-20 12:00:00&quot;);
// 3 months 19 days
</code></pre>
<p>&#x8981;&#x83B7;&#x53D6;&#x539F;&#x59CB;&#x6570;&#x5B57;&#x503C;&#x800C;&#x4E0D;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5219;&#x5C06; <code>true</code> &#x503C;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x7ED9;&#x8BE5;&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre><code class="language-javascript">moment.preciseDiff(m1, m2, true); 
// {years : 0, months : 1, days : 2, hours : 3, minutes : 4, seconds : 5, firstDateWasLater : false}
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">npm install moment-precise-range-plugin
</code></pre>

							</div>
<p>The <a href="javascript:window.open('https://codebox.org.uk/pages/moment-date-range-plugin');" target="_blank" rel="nofollow">Precise Range</a> plugin, written by <a href="javascript:window.open('https://github.com/codebox');" target="_blank" rel="nofollow">Rob Dawson</a>, can be used to display exact, human-readable representations of date/time ranges:</p>
<pre><code class="language-javascript">moment(&quot;2014-01-01 12:00:00&quot;).preciseDiff(&quot;2015-03-04 16:05:06&quot;);
 // 1 year 2 months 3 days 4 hours 5 minutes 6 seconds
</code></pre>
<pre><code class="language-javascript">moment.preciseDiff(&quot;2014-01-01 12:00:00&quot;, &quot;2014-04-20 12:00:00&quot;);
// 3 months 19 days
</code></pre>
<p>To obtain the raw numeric values rather than a string, pass the value <code>true</code> as the third argument to the method:</p>
<pre><code class="language-javascript">moment.preciseDiff(m1, m2, true); 
// {years : 0, months : 1, days : 2, hours : 3, minutes : 4, seconds : 5, firstDateWasLater : false}
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>